﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartSpace.Core;

namespace SmartSpace.Workflow.DriveEvents
{
    /// <summary>
    /// 返回到上一步的操作人
    /// </summary>
    public class SendToPreviousDriveEvent : IWorkflowDriveEvent
    {
        public WorkflowDriveRecord Drive(
            WorkflowInstance instance,
            WorkflowMetadata workflow, 
            ActivityMetadata activity,
            EventMetadata @event,
            WorkflowDriveRecord currentRecord,
            Guid dataId,
            User sender,
            IEnumerable<Guid> receivers)
        {
            // 关闭上一步
            if (currentRecord != null)
            {
                currentRecord.IsActivated = false;
            }

            WorkflowDriveRecord driveRecord = new WorkflowDriveRecord();
            driveRecord.Id = Guid.NewGuid();
            driveRecord.InstanceId = instance.Id;
            driveRecord.WorkflowId = instance.WorkflowId;
            driveRecord.ActivityId = @event.ToActivityId;
            driveRecord.EventId = @event.Id;
            driveRecord.SenderId = sender.Id;
            driveRecord.ReceiverId = currentRecord.SenderId;
            driveRecord.ReceiverType = WfReceiverType.User;
            driveRecord.DrivedDate = DateTime.Now;
            driveRecord.RecordId = dataId;
            driveRecord.IsActivated = true;
            return driveRecord;
        }
    }
}
